package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo3FIlter {
  def main(args: Array[String]): Unit = {
    //创建Spark环境
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("map")

    val sc = new SparkContext(conf)

    //读取数据
    val linesRDD: RDD[String] = sc.textFile("spark/data/students.csv")

    val filterRDD: RDD[String] = linesRDD
      .filter(line => {
        val split: Array[String] = line.split(",")
        val sex: String = split(3)
        val clazz: String = split(4)
        "文科一班".equals(clazz) && "男".equals(sex)
      })

    filterRDD.foreach(println)
  }

}
